package com.ziyun.erp.web.modules.data.controller;

import com.ziyun.erp.modules.data.service.DataTransferService;
import com.ziyun.erp.modules.data.service.OrderInfoExtendService;
import com.ziyun.erp.modules.data.service.OrderItemExtendService;
import com.ziyun.erp.modules.data.vo.OrderInfoVo;
import com.ziyun.erp.modules.production.entity.ErpOrderItemEntity;
import io.renren.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author gaosheng
 * @date 2018-10-11 19:05
 */
@Slf4j
@RestController
@RequestMapping("data/dataTransfer")
public class DataTransferController {

    // todo 自定义参数迁移
    @Autowired
    private DataTransferService dataTransferService;

    @Autowired
    private OrderInfoExtendService orderInfoExtendService;

    @Autowired
    private OrderItemExtendService orderItemExtendService;

    /**
     * 商户数据迁移
     * @return
     */
    @RequestMapping("/sellerInfoDataTransfer")
    public R sellerInfoDataTransfer(){
        return dataTransferService.sellerInfoDataTransfer();
    }

    /**
     * 工厂数据迁移
     * @return
     */
    @RequestMapping("/factoryDataTransfer")
    public R factoryDataTransfer(){
        return dataTransferService.factoryDataTransfer();
    }

    /**
     * 商户图片数据迁移
     * @return
     */
    @RequestMapping("/sellerImageDataTransfer")
    public R sellerImageDataTransfer(@Param("type") String type){
        return dataTransferService.sellerImageDataTransfer(type);
    }

    /**
     * 订单数据迁移
     * @return
     */
    @RequestMapping("/orderInfoDataTransfer")
    public R orderInfoDataTransfer(){

        for (int i = 0; i < 300; i++){
            List<OrderInfoVo> orderInfoVoList = orderInfoExtendService.selectOrderInfoList(null);
            log.info("循环次数：" + (i+1) + ",当前查询条数：" + orderInfoVoList.size());
            System.out.println("循环次数：" + (i+1) + ",当前查询条数：" + orderInfoVoList.size());
            try {
                dataTransferService.saveOrderInfoDataTransfer(orderInfoVoList);
            }catch (Exception e){
                log.info(e.getMessage());
            }
        }
        return R.ok();
    }

    /**
     * 订单商品数据迁移
     * @return
     */
    @RequestMapping("/orderItemDataTransfer")
    public R orderItemDataTransfer(){

        for (int i = 0; i < 200; i++){
            List<ErpOrderItemEntity> list = orderItemExtendService.selectOrderItemList(null);
            log.info("循环次数：" + (i+1) + ",当前查询条数：" + list.size());
            System.out.println("循环次数：" + (i+1) + ",当前查询条数：" + list.size());
            dataTransferService.saveOrderItemDataTransfer(list);
        }

        return R.ok();
    }

    /**
     * 订单商品发货图片数据转移
     * @return
     */
    @RequestMapping("/orderItemSendPicDataTransfer")
    public R orderItemSendPicDataTransfer(){
        return dataTransferService.orderItemSendPicDataTransfer();
    }

    /**
     * 订单成本数据迁移
     * @return
     */
    @RequestMapping("/orderCostDataTransfer")
    public R orderCostDataTransfer(){
        return dataTransferService.orderCostDataTransfer();
    }

    /**
     * 物流信息数据迁移
     * @return
     */
    @RequestMapping("/orderLogisticsDataTransfer")
    public R orderLogisticsDataTransfer(){
        return dataTransferService.orderLogisticsDataTransfer();
    }

}
